package com.dc.kotlinfinance.controller

import com.dc.kotlinfinance.model.StatisticdailyRec
import com.dc.kotlinfinance.service.RequestService
import com.dc.kotlinfinance.service.impl.RequestServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 *@createTime 2017/11/14 0014
 *@author DC
 */
@RestController
@RequestMapping("request")
class RequestController {

    @Autowired
    private lateinit var requestService:RequestService

    @PostMapping("statisticdaily")
    fun statisticdaily(@RequestBody rec: StatisticdailyRec) : Map<String,Any>{
        val res = HashMap<String,Any>(2)
        val flag = rec.startDate == null || rec.endDate == null || rec.mediaProviderId == null
        if (flag){
            res.put("errorCode", 2)
            res.put("message", "数据格式错误")
        }else{
            res.put("data", requestService.statisticdaily(rec))
            res.put("errorCode", 0)
        }
        return res
    }


    @PostMapping("sspstatistic")
    fun sspstatistic(@RequestBody rec: StatisticdailyRec): Any {
        val res = HashMap<String,Any>(2)
        val flag = rec.startDate== null || rec.endDate == null
        if (flag) {
            res.put("errorCode", 2)
            res.put("message", "数据格式错误")
        }
        res.put("data", requestService.sspstatistic(rec))
        res.put("errogCode", 0)
        return res
    }

}